package com.aaa.sbm.service.impl;

import com.aaa.sbm.dao.DeptDao;
import com.aaa.sbm.entity.Dept;
import com.aaa.sbm.service.DeptService;
import com.aaa.sbm.util.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class DeptServiceImpl implements DeptService {

    //依赖注入
    @Resource
    private DeptDao deptDao;

@Override
    public int add(Dept dept) {
    return deptDao.add(dept);
    }

    @Override
    public int update(Dept dept) {
        return deptDao.update(dept);
    }

    @Override
    public int deleteById(int deptNo) {
        return deptDao.deleteById(deptNo);
    }

    @Override
    public PageInfo queryPage(Page<Dept> page) {
        Integer pageNo = page.getPageNo();
        Integer pageSize = page.getPageSize();
        //判断pageNo，pageSize
        if(pageNo==null||pageNo==0||pageSize==null||pageSize==0){
            //直接抛出异常
            throw   new IllegalArgumentException("参数异常!");
        }
        //调用PageHelper设置参数方法，开始分页
        PageHelper.startPage(page.getPageNo(),page.getPageSize());
        //获取dept对象
        Dept data = page.getData();
        //调用dao层查询
        List<Dept> deptList = deptDao.queryByParam(data);
        //使用查询结果封装成返回对象
        return new PageInfo(deptList);
    }
}
